package com.lq.educationsystem.lqcourse.controller;

import com.lq.educationsystem.common.util.PageUtil;
import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.vo.CoursePageVo;
import com.lq.educationsystem.lqcourse.entiy.CourseTb;
import com.lq.educationsystem.lqcourse.service.CourseBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "课程")
@RequestMapping("/course/base")
@RestController
public class CourseBaseController {

    @Autowired
    CourseBaseService courseBaseService;

    //增加


    @Operation(summary = "插入课程信息")
    @PostMapping("/insert")
    public Result insertInfo(@RequestBody CourseTb courseInfo){
        courseBaseService.insertInfo(courseInfo);
        return ResultBuild.buildOk();
    }
    //删除
    @Operation(summary = "通过课程id删除考试信息")
    @PostMapping("/delete")
    public Result deleteById(@RequestBody CourseTb courseInfo){
        Integer courseId = courseInfo.getCourseId();
        //删除

        courseBaseService.deleteById(courseId);
        return ResultBuild.buildOk();

    }
    //更新
    @Operation(summary = "更新考试信息")
    @PostMapping("/update")
    public Result updateInfo(@RequestBody CourseTb courseInfo){
        courseBaseService.updateInfo(courseInfo);
        return ResultBuild.buildOk();
    }
    //通过id查询
    @Operation(summary = "根据课程id查询考试信息")
    @PostMapping("/querybyid")
    public Result<CourseTb> queryById(@RequestBody CourseTb courseInfo){
        Integer courseId = courseInfo.getCourseId();
        //通过id查询
        Result<CourseTb> courseTbResult = courseBaseService.queryById(courseId);

        return courseTbResult;
    }

    //查询数据
    @Operation(summary = "分页查询考试信息")
    @PostMapping("/query")
    public ResultPage<CourseTb> queryList(@RequestBody CoursePageVo coursePageVo){

        ResultPage<CourseTb> courseTbResult = courseBaseService.queryList(coursePageVo);

        return courseTbResult;

    }
}
